/*
 * Copyright (c) 2019 DawnFramework. All Rights Reserved.
 * Licensed under the MIT (LICENSE) license.
 */

package org.dawn.common.service.service;

/**
 * @author Willard Hu on 2017/4/25.
 */
public class ServicePageResponse extends ServiceResponse {
    private static final long serialVersionUID = 8488946365856005098L;

    /** 页码 */
    protected int page;
    /** 总页数 */
    protected int totalPage;
    /** 每页行数 */
    protected int rows;
    /** 查询结果总行数 */
    protected int totalRows;

    /**
     * 继承类需要实现自己的 succ 方法，调用此方法
     */
    protected ServicePageResponse initSuccessedData(ServicePageResponse resp, int page, int rows, int totalCount) {
        resp.setStatusCode(SUCCESS_CODE);
        resp.setPage(page);
        resp.setRows(rows);
        int totalPage = totalCount % rows == 0 ? totalCount / rows : totalCount / rows + 1;
        resp.setTotalPage(totalPage > 0 ? totalPage : 1);
        resp.setTotalRows(totalCount);
        return resp;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getTotalRows() {
        return totalRows;
    }

    public void setTotalRows(int totalRows) {
        this.totalRows = totalRows;
    }
}
